package com.sigmazero13.gameutils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class GamePickerConfig extends Activity {
	EditText numPlayersField;
	EditText maxLengthField;
	Integer defaultNumPlayers = 2;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.picker_config);
		
		numPlayersField = (EditText)this.findViewById(R.id.num_players);
		defaultNumPlayers = Integer.parseInt(numPlayersField.getText().toString());
		
		maxLengthField = (EditText)this.findViewById(R.id.max_time);
		Button pickButton = (Button)this.findViewById(R.id.pick_random_go);
		pickButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent();
				try {
					Integer numPlayers = Integer.parseInt(numPlayersField.getText().toString());
					Integer maxLength = Integer.parseInt(maxLengthField.getText().toString());
					
					i.putExtra("num_players", numPlayers);
					i.putExtra("max_length", maxLength);
					setResult(RESULT_OK, i);
				} catch (NumberFormatException nfe) {
					setResult(RESULT_CANCELED);
				}
				finish();
			}
		});
	}
}
